package com.ebs.md.fxmonitor.marketmonitor.alert;

/**
 * Perforce Revision:
 *  $File: //depot/MarketData/fxmonitor/main/src/main/java/com/ebs/md/fxmonitor/marketmonitor/alert/PassiveHitsNMLMessageCreator.java $
 *  $Revision: #3 $  $Change: 116131 $  $DateTime: 2012/10/23 12:55:07 $  $Author: Arik.Sher $
 */

import java.util.List;

import com.ebs.market.monitor.MarketMonitor.EventType;
import com.ebs.market.monitor.MarketMonitor.MarketIdentfier;
import com.ebs.market.monitor.MarketMonitor.OrderDetail;
import com.ebs.market.monitor.MarketMonitor.PassiveHitsNoMansLandEvent;
import com.ebs.md.fxmonitor.marketmonitor.model.PassiveHitSingleFactNML;


public class PassiveHitsNMLMessageCreator
extends           AbstractAlertMessageCreatorBySingleFact<PassiveHitsNoMansLandEvent, PassiveHitSingleFactNML>
{

	public PassiveHitsNMLMessageCreator(List<PassiveHitSingleFactNML> dataList) {
		super(dataList);
	}

	@Override
	public PassiveHitsNoMansLandEvent createAlertObject() {
		PassiveHitsNoMansLandEvent.Builder builder = PassiveHitsNoMansLandEvent.newBuilder();

		final PassiveHitSingleFactNML firstDataElement = getFirstDataElement();
		{
		MarketIdentfier mi = gpbBuildMarketIdentifier(firstDataElement.getPair());
		builder.setMarketId(mi);
		}
		final String eventId = createEventIdByQuoteId(firstDataElement, firstDataElement.getTimestamp());
		builder.setEventId(eventId);
		builder.setEventTime(eventTimeMillis);
		builder.setConfigInstanceName(firstDataElement.getConfigInstanceName());
		{
		OrderDetail od = gpbBuildOrderDetail(firstDataElement);
		builder.setFirstQuote(od);
		}
		
		if ( firstDataElement.getBestRate() != null ) {
			builder.setBestRate(firstDataElement.getBestRate().toString());
		}
		//TODO: remove the setWorstRate, not alerting based on it at all
//		builder.setWorstRate()
		
		// set causing Quote IDs
		for ( PassiveHitSingleFactNML curr : dataList ) {
			builder.addQuoteIds(curr.getQuoteId());
		}
		
		return builder.build();
	}

	@Override
	public EventType getEventType() {
		return EventType.PASSIVE_HITS_NO_MANS_LAND;
	}

}
